<?php

namespace app\api\controller\exchange;

use app\api\service\exchange\ExchangeService;
use app\api\service\google\GoogleService;
use hunma\basic\ApiResponse;
use hunma\basic\BaseController;

class ExchangeController extends BaseController
{
    protected $service;

    /**
     * 构造函数，初始化服务对象
     */
    public function __construct()
    {
        $this->service = new ExchangeService();
    }

    public function get()
    {
        $rules = [
            ['from', 'require', '源货币不能为空'],
            ['to', 'require', '目标货币不能为空'],
            ['amount', 'require|number', '金额不能为空|金额必须是数字'],
        ];

        $this->parseValidationRules($rules);
        return ApiResponse::success($this->service->get(self::getAllParams()));
    }
}